package br.com.duosoftware.controllers;

import br.com.duosoftware.daos.InscricaoDAO;
import br.com.duosoftware.entidades.Inscricao;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Daniel
 *
 */
@WebServlet(name = "InscricaoServler", urlPatterns = {"/doInsc"})
public class InscricaoServlet extends HttpServlet {

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     *
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String pagina = "sucesso.jsp";
        
        Inscricao inscricao = new Inscricao(request.getParameter("nome")
                                          , request.getParameter("telefone")
                                          , request.getParameter("celular")
                                          , request.getParameter("email")
                                          , request.getParameter("experiencia")
                                          , request.getParameter("descricao"));

        InscricaoDAO inscricaoDAO = new InscricaoDAO();

        try {

            inscricaoDAO.add(inscricao);

        } catch (SQLException ex) {

            ex.printStackTrace();

            pagina = "erro.jsp";
            
        }

        response.sendRedirect(pagina);
        
    }

}
